package cn.lliiooll.launcher.thread;

import java.io.*;

public class FileRead implements Runnable{
	
	static String filepath;
	static String pm;
	
	public FileRead(){
		Thread t = new Thread(this,"FileRead");
		t.run();
	}
	
	public static String read(String filepath){
		FileRead.filepath = filepath;
		new FileRead();
		return FileRead.pm;
	}

	@SuppressWarnings("resource")
	@Override
	public void run() {
		File f = new File(filepath);
		pm = null;
		if(f.exists()) {
			try {
				FileInputStream fin = new FileInputStream(f);
				int i = 0;
				int n = 0;
				byte[] b = new byte[1024];
				while((i = fin.read()) != -1) {
					b[n] = (byte) i;
					n++;
				}
				pm = new String(b,0,n);
			} catch (FileNotFoundException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			} catch (IOException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}else {
			pm = null;
		}
		
		
	}
}
